import { ref } from 'vue';
import DepartmentModal from '@/views/main/system/department/children/department-modal.vue';
type TEditCallback = (data: any) => void;
type TCreateCallback = () => void;
function usePageModal(editCallback?: TEditCallback, createCallback?: TCreateCallback) {
  const modalRef = ref<InstanceType<typeof DepartmentModal>>();
  /**
   * @function handleCreateRecord modal组件中的创建记录
   * @param record 创建记录
   */
  function handleCreateRecord() {
    modalRef.value?.openModal(true);
    if (createCallback) createCallback();
  }

  /**
   * @function handleEditRecord modal罪案中编辑记录
   * @param record 编辑记录
   */
  function handleEditRecord(record: any) {
    modalRef.value?.openModal(false, record);
    if (editCallback) {
      editCallback(record);
    }
  }
  return {
    modalRef,
    handleCreateRecord,
    handleEditRecord
  };
}

export default usePageModal;
